package com.qyhl.webtv.commonlib.common;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.launcher.ARouter;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.constant.AppConfigConstant;
import com.qyhl.webtv.commonlib.constant.ServicePathConstant;
import com.qyhl.webtv.commonlib.entity.VersionBean;
import com.qyhl.webtv.commonlib.entity.config.MessageDetailBean;
import com.qyhl.webtv.commonlib.entity.news.NewsStyleBean;
import com.qyhl.webtv.commonlib.service.ChannelConfigService;
import com.qyhl.webtv.commonlib.service.UserService;
import com.qyhl.webtv.commonlib.utils.config.AppConfigUtil;

import java.util.List;
import java.util.Map;

/**
 * 通用工具类
 *
 * @author helin
 * @date 2019年4月2日17:27:43
 */
public class CommonUtils {

    /**
     * 配置系统
     */
    @Autowired(name = ServicePathConstant.GET_CONFIG_INFO)
    public ChannelConfigService configService;

    /**
     * 用户中心
     */
    @Autowired(name = ServicePathConstant.USER_SERICE)
    public UserService userService;


    private static CommonUtils commonUtils;

    public static CommonUtils getInstance() {
        if (commonUtils == null) {
            commonUtils = new CommonUtils();
        }
        return commonUtils;
    }

    private CommonUtils() {
        ARouter.getInstance().inject(this);
    }


    /**
     * 是否登陆
     *
     * @param callBack
     */
    public void isLogin(UserService.LoginCallBack callBack) {
        userService.checkUserLogin(callBack);
    }

    /**
     * 获取站点
     *
     * @return
     */
    public int getSite() {
        return configService.getSiteId();
    }

    /**
     * 获取站点别称
     *
     * @return
     */
    public String getSiteName() {
        return configService.getSITE_NAME();
    }

    /**
     * 设置站点别称
     *
     * @param siteName
     */
    public void setSiteName(String siteName) {
        configService.setSiteName(siteName);
    }

    /**
     * 设置抽奖连接
     *
     * @param url
     */
    public void setLuckDrawUrl(String url) {
        configService.setLuckDrawUrl(url);
    }


    /**
     * 获取用户名
     *
     * @return
     */
    public String getUserName() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.USER_NAME) + "";
    }

    public String getUserCheck() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.USER_CHECK) + "";
    }

    public String getUserCheckReason() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.USER_CHECK_REASON) + "";
    }


    /**
     * 链接是否开启分享
     *
     * @return
     */
    public int getLinkUrlShare() {
        return (int) AppConfigUtil.getInstance().getConValue(AppConfigConstant.LINK_URL_SHARE);
    }


    /**
     * 新闻样式
     *
     * @return
     */
    public boolean getGlobalStyle() {
        return (boolean) AppConfigUtil.getInstance().getConValue(AppConfigConstant.GLOBAL_STYLE);
    }

    /**
     * 新闻样式列表
     *
     * @return
     */
    public List<NewsStyleBean> getGlobalStyleBeanList() {
        return (List<NewsStyleBean>) AppConfigUtil.getInstance().getConValue(AppConfigConstant.STYLE_BEAN_LIST);
    }

    /**
     * 获取置顶消息
     *
     * @return
     */
    public List<MessageDetailBean> getTopMessage() {
        return (List<MessageDetailBean>) AppConfigUtil.getInstance().getConValue(AppConfigConstant.TOPMESSAGE);
    }


    /**
     * 最小评论数
     *
     * @return
     */
    public String getCommentNum() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.COMMENT_NUM) + "";
    }


    /**
     * 最小播放数
     *
     * @return
     */
    public String getMinPlay() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.MIN_PLAY) + "";
    }

    /**
     * 获取用户头像
     *
     * @return
     */
    public String getUserLogo() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.HEAD_ICON) + "";
    }

    /**
     * CMS地址
     *
     * @return
     */
    public String getCmsUrl() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.HTTP_CODE_URL) + "";
    }

    public String getCode() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.CODE) + "";
    }

    /**
     * 获取评论规则
     *
     * @return
     */
    public String getCommentRule() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.COMMENT_RULE) + "";
    }

    public String getGlobalVideo() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.GLOBAL_VIDEO) + "";
    }

    public String getGlobalCommon() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.GLOBAL_COMMON) + "";
    }

    public Map<String, String> getReadHistory() {
        return (Map<String, String>) AppConfigUtil.getInstance().getConValue(AppConfigConstant.READ_HISTORY);
    }

    public boolean getHasHistory() {
        try {
            return (boolean) AppConfigUtil.getInstance().getConValue(AppConfigConstant.HAS_HISTORY);
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 乡镇
     *
     * @return
     */
    public String getCountrysideId() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.COUNTRYSIDEID) + "";
    }

    /**
     * 政务
     *
     * @return
     */
    public String geTaffairsId() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.AFFAIRSID) + "";
    }

    /**
     * 轮播数量
     *
     * @return
     */
    public String getSectionBannerNum() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.SECTION_BANNER_NUM) + "";

    }

    /**
     * 获取轮播数量
     *
     * @return
     */
    public int getBannerNum() {
        return Integer.parseInt(AppConfigUtil.getInstance().getConValue(AppConfigConstant.BANNER_NUM) + "");
    }

    /**
     * 获取孔子到家状态
     *
     * @return
     */
    public String getShortVideoState() {
        return (String) AppConfigUtil.getInstance().getConValue(AppConfigConstant.SHORT_VIDEO_STATE);
    }

    /**
     * 获取用户昵称
     *
     * @return
     */
    public String getNickName() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.NICK_NAME) + "";
    }

    /**
     * 获取性别
     *
     * @return
     */
    public String getSex() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.SEX) + "";
    }

    /**
     * 获取邮箱
     *
     * @return
     */
    public String getEmail() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.EMAIL) + "";
    }

    /**
     * 积分开关
     *
     * @return
     */
    public String getIntergralSwitch() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.INTEGRAL_SWITCH) + "";
    }


    /**
     * 获取名称
     */
    public String getAppName() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.APP_NAME) + "";
    }

    /**
     * 获取广告开关
     *
     * @return
     */
    public String getOtherAdv() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.OTHER_ADV) + "";
    }

    /**
     * 获取广告开关
     *
     * @return
     */
    public String getHomeAdv() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.HOMEADV) + "";
    }

    /**
     * 添加默认数据
     *
     * @param key
     * @param value
     */
    public void putConfigData(String key, Object value) {
        AppConfigUtil.getInstance().setConValue(key, value);
    }

    /**
     * 获取版本信息
     *
     * @return
     */
    public VersionBean.DataBean getVersionData() {
        return (VersionBean.DataBean) AppConfigUtil.getInstance().getConValue(AppConfigConstant.VERSION_BEAN);
    }

    /**
     * 邀请码
     *
     * @return
     */
    public String getInviteCode() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.INVITE_CODE) + "";
    }

    /**
     * 获取列表广告
     *
     * @return
     */
    public String getListAdv() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.LIST_ADV) + "";
    }

    /**
     * 获取栏目Id
     *
     * @return
     */
    public String getSectionId() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.SECTIONID) + "";
    }

    /**
     * 广告地址
     *
     * @return
     */
    public String getAdvUrl() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.ADVURL) + "";
    }

    /**
     * 专题Id
     *
     * @return
     */
    public String getSpecialId() {
        return AppConfigUtil.getInstance().getConValue(AppConfigConstant.SPECIAL_ID) + "";
    }

    /**
     * 获取App图标
     *
     * @return
     */
    public int getAppLauncherIcon() {
        return configService.getAppLauncherIcon();
    }

    /**
     * 获取图文直播地址
     *
     * @return
     */
    public String getSceneUrl() {
        return configService.getSceneUrl();
    }

    /**
     * 获取文明办地址
     *
     * @return
     */
    public String getCivilizedUrl() {
        return configService.getCivilizedUrl();
    }

    /**
     * 获取孔子到家小视频地址
     *
     * @return
     */
    public String getMicroVideo() {
        return configService.getMicroVideoUrl();
    }

    /**
     * 活动地址
     *
     * @return
     */
    public String getActivityUrl() {
        return configService.getActivityUrl();
    }

    /**
     * 圈子地址
     *
     * @return
     */
    public String getCircleUrl() {
        return configService.getCircleUrl();
    }

    /**
     * 用户中心地址
     *
     * @return
     */
    public String getUserCenterUrl() {
        return configService.getUserCenterUrl();
    }

    /**
     * 好店地址
     *
     * @return
     */
    public String getShopUrl() {
        return configService.getShopUrl();
    }

    /**
     * 积分商城地址
     *
     * @return
     */
    public String getScoreUrl() {
        return configService.getScoreUrl();
    }

    /**
     * 聊天室地址
     *
     * @return
     */
    public String getChatRoomUrl() {
        return configService.getChatRoomUrl();
    }

    /**
     * UM数据
     *
     * @return
     */
    public String getUMAppKey() {
        return configService.getUMAppKey();
    }

    public String getUMChannelId() {
        return configService.getUMChannlId();
    }


    /**
     * Socket聊天室地址
     *
     * @return
     */
    public String getSocketUrl() {
        return configService.getSocketUrl();
    }

    /**
     * 发票抽奖地址
     *
     * @return
     */
    public String getLuckDrawUrl() {
        return configService.getLuckDrawUrl();
    }

    /**
     * 积分地址
     *
     * @return
     */
    public String getIntegralUrl() {
        return configService.getIntegralUrl();
    }

    /**
     * 聊天室id
     *
     * @return
     */
    public String getLeanCloudAppid() {
        return configService.getLeanCloudAppid();
    }

    /**
     * 缓存地址
     *
     * @return
     */
    public String getCachePath() {
        return configService.getCachePath();
    }

    /**
     * 聊天室key
     *
     * @return
     */
    public String getLeanCloudAppkey() {
        return configService.getLeanCloudAppkey();
    }

    /**
     * 投诉
     *
     * @return
     */
    public String getComplainUrl() {
        return configService.getComplainUrl();
    }

    /**
     * 金币收益页面
     *
     * @return
     */
    public String getGoldUrl() {
        return configService.getGoldUrl();
    }

    /**
     * 获取配置系统地址
     *
     * @return
     */
    public String getBaseUrl() {
        return configService.getBaseUrl() + "App_Config/";
    }

    /**
     * 基础地址
     *
     * @return
     */
    public String getAppConfigUrl() {
        return configService.getBaseUrl();
    }

    /**
     * rec新闻
     *
     * @return
     */
    public String getRecNewsUrl() {
        return configService.getRecNewsUrl();
    }

    /**
     * 广告BannerId
     *
     * @return
     */
    public String getBannerId() {
        return configService.getBannerID();
    }


    /**
     * 小米Id
     *
     * @return
     */
    public String getXiaoMiId() {
        return configService.getXiaoMiId();
    }

    /**
     * 小米Key
     *
     * @return
     */
    public String getXiaoMiKey() {
        return configService.getXiaoMiKey();
    }

    /**
     * OppoKey
     *
     * @return
     */
    public String getOppoAppKey() {
        return configService.getOppoAppKey();
    }

    /**
     * OppoSecret
     *
     * @return
     */
    public String getOppoAppSecret() {
        return configService.getOppoAppSecret();
    }


    /**
     * QQ分享
     *
     * @return
     */
    public String getSHARE_QQ_APPID() {
        return configService.getSHARE_QQ_APPID();
    }

    public String getSHARE_QQ_APPSECRET() {
        return configService.getSHARE_QQ_APPSECRET();
    }

    /**
     * 微信分享
     *
     * @return
     */
    public String getSHARE_WEIXIN_APPSECRET() {
        return configService.getSHARE_WEIXIN_APPSECRET();
    }

    public String getSHARE_WEIXIN_APPID() {
        return configService.getSHARE_WEIXIN_APPID();
    }


    public String getPrivacyUrl() {
        return configService.getPrivacy();
    }


    public String getQuestionUrl() {
        return configService.getQuestionUrl();
    }

    public String getSchoolUrl(){
        return configService.getSchoolUrl();
    }

    public String getPtgId() {
        return configService.getPtgAdId();
    }

    public String getPtgSecret() {
        return configService.getPtgAdSecret();
    }

    public String getPtgSplashId() {
        return configService.getPtgSplashId();
    }

    public String[] getPtgHomeId() {
        return configService.getPtgHomeId();
    }

    public String getPtgDetailId() {
        return configService.getPtgDetailId();
    }


    public String getSdkListUrl() {
        return configService.getSdkListUrl();
    }

    public String getHLSchoolUrl(){
        return configService.getHLSchoolUrl();
    }

}
